<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/res/css/simple.css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/res/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/res/jquery.form.js" ></script>
<title>供货商管理</title>
<script>
function add(){
	$("#edit_form")[0].reset();
	$("#id").val('');
	$("#div_edit").toggle();
}
function edit(id){
	$("#div_edit").show();
	var url = '<%=request.getContextPath() %>/employee/load.do?id='+id;
	var callback = function(data){
		if(data.success != 1)return;
		$("#id").val(data.id);
		$("#name").val(data.name);
		
		$("#area").attr("value",data.area);
		$("#code").val(data.code);
		$("#level").val(data.level);
	};
	$.post(url, null,callback,'json').error(function() { alert('操作失败！'); });
}
function del(id){
	if(!confirm("确定要删除数据吗？")){
		return; 
	}
	var url = '<%=request.getContextPath() %>/employee/del.do?id='+id;
	var callback = function(data){
		if(data == "1"){
			location.reload();
 	  	}else if(data == "-1"){
 	  		alert("删除失败");
 	  	}else{
 	  		alert("系统繁忙，请稍后再试   [data:"+data+"]");
 	  	}
	};
	$.post(url, null,callback,'json').error(function() { alert('删除失败！'); });
}
function save(){
	var queryString = $('#edit_form').formSerialize();
	var url = '<%=request.getContextPath() %>/employee/save.do';
	var callback = function(data){
		if(data == "1"){
			location.reload();
 	  	}else if(data == "-1"){
 	  		alert("保存失败");
 	  	}else{
 	  		alert("系统繁忙，请稍后再试   [data:"+data+"]");
 	  	}
	};
	$.post(url, queryString,callback,'json').error(function() { alert('操作失败！'); });
}
</script>
</head>
<body>
<jsp:include page="/admin/header.jsp" flush= "true ">
      <jsp:param name="m" value="employee"   />
</jsp:include>
<div style="margin:0 auto;width: 90%;" >
<a href="javascript:add();" ><span style="vertical-align:middle;"><img src="<%=request.getContextPath() %>/res/images/add2.gif"></span>添加</a> &nbsp;
<hr />
<div id="div_edit" style="display: none" >
	<form action="" method="post" id="edit_form" >
		<input type="hidden" id="id" name="id" />
		<table>
			<tr><td align="right">员工姓名：</td><td><input type="text" id="name" name="name" /></td></tr>
			<tr><td align="right">手机号码：</td><td><input type="text" id="tel" name="tel" /></td></tr>
			<tr><td>&nbsp;</td><td><input type="button" value="保存" onclick="save();" >&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="清空" onclick="$('#edit_form')[0].reset();" ></td></tr>
		</table>
	</form>
	<hr/>
</div>
<table class="myTable" >
	<tr class="chtr" >
		<td width="30" >&nbsp;</td><td width="150" >员工姓名</td><td width="100">手机号码</td><td width="120px">&nbsp;</td>
	</tr>
	<c:forEach items="${data }" var="d" varStatus="i" >
	<tr>
		<td align="center" >${d.id }</td><td>${d.name}</td><td>${d.tel}</td>
		<td>
		&nbsp;<a href="javascript:edit(${d.id });" ><span style="vertical-align:middle;"><img src="<%=request.getContextPath() %>/res/images/edit.gif"></span>修改</a>&nbsp;
		&nbsp;<a href="javascript:del(${d.id });" ><span style="vertical-align:middle;"><img src="<%=request.getContextPath() %>/res/images/delete.gif"></span>删除</a>&nbsp;
		</td>
	</tr>
	</c:forEach>
</table>
</div>
<%@include file="/admin/bottom.jsp" %>
</body>
</html>
